<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style media="screen">
    </style>
</head>
<body>
    <div id="root"></div>
    <script src="../../js/react.js" charset="utf-8"></script>
    <script src="../../js/react-dom.js" charset="utf-8"></script>
    <script src="../../js/browser.min.js" charset="utf-8"></script>
    <script type="text/babel">
        class CounterButton extends React.Component {
            constructor(props) {
                super(props);
                this.state = {count: 1};
            }

            shouldComponentUpdate(nextProps, nextState) {
                if (this.props.color !== nextProps.color) {
                  return true;
                }

                if (this.state.count !== nextState.count) {
                  return true;
                }
                return false;
            }

            render() {
                return (
                    <button
                      color={this.props.color}
                      onClick={() => this.setState(state => ({count: state.count + 1}))}>
                      Count: {this.state.count}
                    </button>
                )
            }
        }

        class ListOfWords extends React.PureComponent {
          render() {
            return <div>{this.props.words.join(',')}</div>;
          }
        }

        class WordAdder extends React.Component {
          constructor(props) {
            super(props);
            this.state = {
              words: ['marklar']
            };
            this.handleClick = this.handleClick.bind(this);
          }

          handleClick() {
            // This section is bad style and causes a bug
            const words = this.state.words;
            words.push('marklar');
            this.setState({words: words});
          }

          render() {
            return (
              <div>
                <button onClick={this.handleClick}>click</button>
                <ListOfWords words={this.state.words} />
              </div>
            );
          }
        }


        ReactDOM.render(
            <WordAdder/>,
            document.getElementById('root')
        )
    </script>
</body>
</html>
